home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / lisp.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  6KB  |  304 lines

  1. /* Changes to track when merging:
  2.    Changes in stack.c to support backtrace changes
  3.    Changes in infrun to support .o loading
  4.    add lisp.c and lisp.o to Makefile.in
  5.    Modify top-level README
  6.    maybe symtab.c if we fix that stuff.
  7.    dbxread.c: remove no debug symbols found msg.
  8. */
  9.  
  10. #include <string.h>
  11. #include <stdio.h> 
  12. #include "defs.h"
  13. #include "param.h"
  14. #include "frame.h"
  15. #include "symtab.h"
  16. #include "value.h"
  17. #include "expression.h"
  18. #include "gdbcore.h"
  19. #include "gdbcmd.h"
  20. #include "target.h"
  21.  
  22. extern char *xmalloc ();
  23.  
  24. #define CHAR_TO_NUMBER(c) ((c <= '9') ? c - '0' : c + 10 - 'A')
  25.  
  26. int lisp_name_p(name)
  27.      char* name;
  28. {
  29.   return((name != NULL) &&
  30.      (strchr("pmsvftb",*name) != NULL) &&
  31.      (*(name + 1) == '_'));
  32. }
  33.  
  34. char hex_to_ascii(hex)
  35.      char* hex;
  36. {
  37.   return((CHAR_TO_NUMBER(hex[0]) * 16) + CHAR_TO_NUMBER(hex[1]));
  38. }  
  39.  
  40. void print_lisp_name(name)
  41.      char* name;
  42. {
  43.   char c;
  44.  
  45.   c = *name;
  46.   name = name + 2;
  47.   if (strchr("spm",c) != NULL) {
  48.     name = strchr(name,'_');
  49.     if (name == NULL) {
  50.       printf("Lisp naming error: no package found\n");
  51.     }
  52.     name = name + 1;
  53.   }
  54.   c = *name;
  55.   while (c != '\0') {
  56.     if (c == '_') {
  57.       c = hex_to_ascii(name + 1);
  58.       putchar(c);
  59.       name = name + 3; 
  60.     } else {
  61.       putchar(c);
  62.       name = name + 1;
  63.     }
  64.     c = *name;
  65.   }
  66. }
  67.  
  68. char *lisp_demangle(name)
  69.      char *name;
  70. {
  71.   char c,*new,*tmp;
  72.  
  73.   if (lisp_name_p(name)) {
  74.     new = (char *) xmalloc(strlen(name));
  75.     tmp = new;
  76.     c = *name;
  77.     name = name + 2;
  78.     if (strchr("spm",c) != NULL) {
  79.       name = strchr(name,'_');
  80.       if (name == NULL) {
  81.     printf("Lisp naming error: no package found\n");
  82.     return(NULL);
  83.       }
  84.       name = name + 1;
  85.     }
  86.     c = *name;
  87.     while (c != '\0') {
  88.       if (c == '_') {
  89.     c = hex_to_ascii(name + 1);
  90.     *tmp = c;
  91.     tmp = tmp + 1;
  92.     name = name + 3; 
  93.       } else {
  94.     *tmp = c;
  95.     tmp = tmp + 1;
  96.     name = name + 1;
  97.       }
  98.       c = *name;
  99.     }
  100.     *tmp = 0;
  101.     return(new);
  102.   } else {
  103.     return(NULL);
  104.   }
  105. }
  106.  
  107. lisp_strcmp(mangled,normal)
  108.       char* mangled; char* normal;
  109. {
  110.   return(strcmp(mangled,normal));
  111.   if ((((*mangled ==  'v')  ||(*mangled == 'p')) && (*(mangled + 1) == '_')) &&
  112.       (*mangled != *normal)) {
  113.     printf("lisp_strcmp: %s to %s\n",mangled,normal);
  114.     if (*mangled == 'v') {
  115.       mangled = mangled + 2;    /*  skip: v_ */
  116.     } else {
  117.       mangled = mangled + 6;    /*  skip: p_pkg_ */
  118.     }
  119.     while ((*normal != NULL) && (*mangled != NULL))  {
  120.       if (toupper(*normal) == *mangled) {
  121.     normal = normal + 1;
  122.     mangled = mangled + 1;
  123.       } else {
  124.     if ((*mangled == '_') && (*normal == hex_to_ascii(mangled + 1))) {
  125.       normal = normal + 1;
  126.       mangled = mangled + 3;
  127.     } else {
  128.       return(strcmp(mangled,normal));
  129.     }
  130.       }
  131.     }
  132.     if (*mangled == '_') {
  133.       mangled = mangled + 1;
  134.       /*  skip trialing number or return false if other stuff */
  135.       while (*mangled != NULL) {
  136.     if (isdigit(*mangled)) {
  137.       mangled = mangled + 1;
  138.     } else {
  139.       break;
  140.     }
  141.       }
  142.     }
  143.   }
  144.   return(strcmp(mangled,normal));
  145. }
  146.  
  147. char* hidden_lisp_frames[] = { "apply_function", "apply_function_1", NULL };
  148.  
  149. int find_special_frame_entry(function_name)
  150.      char* function_name;
  151. {
  152.   if ((function_name != NULL) &&
  153.       (strcmp(function_name,"eval_closure_code")) == 0) {
  154.     return(1);
  155.   } else {
  156.     return(0);
  157.   }
  158.  
  159. print_special_lisp_frame(index)
  160.      int index;
  161. {
  162.   fflush(stdout);
  163.   /* This relies on the selected_frame being correct */
  164.   parse_and_eval("p_lsp_GDBBACKTRACE(1,name)",1);
  165.   fprintf_filtered(stdout," (interpreted)"); 
  166. }
  167.  
  168. int hide_frames = 1;
  169.  
  170. static void
  171. hide_command(exp)
  172.      char* exp;
  173. {
  174.   hide_frames = ((hide_frames == 0) ? 1 : 0);
  175. }
  176.  
  177.  
  178. hidden_lisp_frame_p(function_name)
  179.      char* function_name;
  180. {
  181.   int i;
  182.  
  183.   if (hide_frames && (function_name != NULL)) {
  184.     /* Hide all eval frames except function calls. */
  185.     if (((strstr(function_name,"p_lsp_EVAL_")) != 0) &&
  186.     (find_special_frame_entry(function_name) == 0)) {
  187.       return(1);
  188.     } else {
  189.       for (i = 0; (hidden_lisp_frames[i] != NULL); i = i + 1) {
  190.     if (strcmp(hidden_lisp_frames[i],function_name)  == 0) {
  191.       return(1);
  192.     }
  193.       }
  194.     }
  195.   }
  196.   return(0);
  197. }
  198.  
  199. static void
  200. lprint_command(exp)
  201.      char* exp;
  202. {
  203.   char buffer[1024];
  204.  
  205.   sprintf(buffer,"p_lsp_GDBPRINT(1,%s)",exp);
  206.   parse_and_eval(buffer,1);
  207. }
  208.  
  209. static void
  210. leval_command(exp)
  211.      char* exp;
  212. {
  213.   char *addr_exp;
  214.   FRAME frame;
  215.   struct frame_info *fi;
  216.   struct symbol *func;
  217.   char *funname = 0;
  218.   extern FRAME parse_frame_specification ();
  219.   extern int so_list_head;    /* lie... */
  220.  
  221.   if (so_list_head == 0) {
  222.     printf("Issue the sharedlib library command before using eval.\n");
  223.   } else {
  224.     char buffer[1024];
  225.  
  226.     frame = parse_frame_specification (addr_exp);
  227.     fi = get_frame_info (frame);
  228.     func = get_frame_function (frame);
  229.     if (exp == 0) {
  230.       exp = "0";
  231.     }
  232.     if (func == 0 || (find_special_frame_entry(SYMBOL_NAME(func)) == 0)) {
  233.       sprintf(buffer,"p_lsp_NULLEVALDEBUG(1,%s) \0",exp);
  234.     } else {
  235.       sprintf(buffer,"p_lsp_EVALDEBUG(7, %s, name, evaled_args, venv, fenv, tenv, benv) \0",exp);
  236.     }
  237.     parse_and_eval(buffer,1);
  238.   }
  239. }
  240.  
  241.  
  242. static void
  243. lisp_abort_command (arg, from_tty)
  244.      char *arg;
  245.      int from_tty;
  246. {
  247.   extern int so_list_head;    /* lie... */
  248.   if (so_list_head == 0) {
  249.     printf("Issue the sharedlib library command before using abort.\n");
  250.   } else {
  251.     printf("Aborting to top-level\n");
  252.     jump_command("abort_to_top_level",from_tty);
  253.   }
  254. }
  255.  
  256.  
  257. static void
  258. lisp_restart_command (arg, from_tty)
  259.      char *arg;
  260.      int from_tty;
  261. {
  262.   extern int so_list_head;    /* lie... */
  263.  
  264.   int n = -1;
  265.   if (arg) {
  266.     n = parse_and_eval_address(arg);
  267.   }
  268.   if (so_list_head == 0) {
  269.     printf("Issue the sharedlib library command before using restart.\n");
  270.   } else {
  271.     printf("Restarting\n");
  272.     jump_command("select_restart_option",from_tty);
  273.   }
  274. }
  275.  
  276. static void
  277. restart_info (exp, from_tty)
  278.      char *exp;
  279.      int from_tty;
  280. {
  281.   parse_and_eval("p_lsp_SHOW_2DRESTARTS(0)");
  282. }
  283.  
  284.  
  285. _initialize_lisp ()
  286. {
  287.   add_com ("hide", class_vars, hide_command,"Hide some stack frames");
  288.  
  289.   add_com ("lp", class_vars, lprint_command,"Call Lisp Printer");
  290.  
  291.   add_com ("eval", class_vars, leval_command,
  292.            "Call Lisp Interpreter with current frame's environment");
  293.  
  294.   add_com ("abort", class_run, lisp_abort_command,
  295.        "Abort to top-level");
  296.  
  297.   add_com ("restart", class_run, lisp_restart_command,
  298.        "Select a restart option");
  299.  
  300.   add_info("restarts", restart_info, "Show available restart options");
  301. }
  302.  
  303.